#include <iostream>

#include "Repeat.hpp"

#include "Expression.hpp"
#include "ExpressionValue.hpp"

Repeat::Repeat(Expression* _condition, Instruction* _codeBoucle)
{
    condition = _condition;
    codeBoucle = _codeBoucle;
}

void Repeat::execute()
{
  codeBoucle->execute();
  condition->compute();
  while( getBoolean(condition->getValue()) == true )
  {
    codeBoucle->execute();
  }
}

void Repeat::display(const unsigned int shift) const
{
    std::cout << "do\n";
    std::cout << "{\n";
        std::cout << "\t";
        codeBoucle->display();
        std::cout << "\n";
    std::cout << "} while (";
    condition->display();
    std::cout << ");\n";
}

Repeat::~Repeat(){}
